//
//  HSServiceCell.m
//  HolyShit
//
//  Created by Robin on 2016/11/18.
//  Copyright © 2016年 HolyShit. All rights reserved.
//

#import "HSServiceCell.h"

@interface HSServiceCell ()

@property (nonatomic, strong) UIImageView *thumbImgV;
@property (nonatomic, strong) UIImageView *headImgV;
@property (nonatomic, strong) UILabel *nameLb;
@property (nonatomic, strong) UILabel *titleLb;
@property (nonatomic, strong) UILabel *descLb;
@property (nonatomic, strong) UILabel *sortLb;
@property (nonatomic, strong) UILabel *focusLb;
@property (nonatomic, strong) UILabel *askLb;

@end

@implementation HSServiceCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    
    // Configure the view for the selected state
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self commonInit];
    }
    return self;
}

- (void)commonInit
{
    [self my_setSelectedBg];
    //    self.selectionStyle = UITableViewCellSelectionStyleNone;
    self.backgroundColor = WHITE_COLOR;
    self.width = ScreenWidth;
    [self addSubview:self.thumbImgV];
    [self addSubview:self.headImgV];
    [self addSubview:self.nameLb];
    [self addSubview:self.titleLb];
    [self addSubview:self.descLb];
    [self addSubview:self.sortLb];
    [self addSubview:self.focusLb];
    [self addSubview:self.askLb];
    if (ServiceType == 1) {
        [self.thumbImgV mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.mas_equalTo(0);
            make.top.mas_equalTo(50);
            make.height.mas_equalTo(180);
        }];
        [self.headImgV mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(10);
            make.top.mas_equalTo(20);
            make.width.height.mas_equalTo(50);
        }];
        [self.nameLb mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.headImgV.mas_right).offset(8);
            make.top.equalTo(self.headImgV.mas_top).offset(3);
        }];
        [self.titleLb mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.nameLb.mas_right).offset(9);
            make.centerY.equalTo(self.nameLb.mas_centerY);
        }];
        [self.descLb mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.headImgV.mas_left);
            make.right.mas_equalTo(-10);
            make.top.equalTo(self.thumbImgV.mas_bottom).offset(10);
        }];
        [self.sortLb mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.headImgV.mas_left);
            make.top.equalTo(self.descLb.mas_bottom).offset(15);
        }];
        [self.focusLb mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.sortLb.mas_right).offset(15);
            make.centerY.equalTo(self.sortLb.mas_centerY);
        }];
        [self.askLb mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.focusLb.mas_right).offset(15);
            make.centerY.equalTo(self.focusLb.mas_centerY);
        }];
    }
    else if(ServiceType == 2){
        [self.thumbImgV mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.mas_equalTo(0);
            make.height.mas_equalTo(355);
        }];
        [self.descLb mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(@10);
            make.right.mas_equalTo(-10);
            make.top.equalTo(self.thumbImgV.mas_bottom).offset(10);
        }];
        [self.headImgV mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(10);
            make.top.equalTo(self.descLb.mas_bottom).offset(10);
            make.width.height.mas_equalTo(25);
        }];
        [self.nameLb mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.headImgV.mas_right).offset(8);
            make.centerY.equalTo(self.headImgV);
        }];
        [self.askLb mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.mas_equalTo(-15);
            make.centerY.equalTo(self.nameLb);
        }];
        [self.focusLb mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self.askLb.mas_left).offset(-15);
            make.centerY.equalTo(self.askLb);
        }];
        self.sortLb.hidden = self.titleLb.hidden = YES;
    }
    else{
        [self.descLb mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(@10);
            make.right.mas_equalTo(-10);
            make.top.mas_equalTo(15);
        }];
        [self.thumbImgV mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.descLb.mas_bottom).offset(10);
            make.left.right.equalTo(self.descLb);
            make.height.mas_equalTo(180);
        }];
        [self.headImgV mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(10);
            make.top.equalTo(self.thumbImgV.mas_bottom).offset(10);
            make.width.height.mas_equalTo(25);
        }];
        [self.nameLb mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.headImgV.mas_right).offset(8);
            make.centerY.equalTo(self.headImgV);
        }];
        [self.titleLb mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.nameLb.mas_right).offset(9);
            make.centerY.equalTo(self.nameLb.mas_centerY);
        }];
        self.sortLb.hidden = self.focusLb.hidden = self.askLb.hidden = YES;
    }
    [self showLineForDirection:MYDirectionBottom];
}

- (void)setModel:(HSMainAskModel *)model
{
    _model = model;
    [self.thumbImgV my_setImage:model.picurl];
    [self.headImgV my_setImage:model.headpicurl];
    self.nameLb.text = model.name;
    self.titleLb.text = model.title;
    self.descLb.text = model.alias;
    self.sortLb.text = model.classification;
    self.focusLb.text = [NSString stringWithFormat:@"%lu人 关注", model.concernCount];
    self.askLb.text = [NSString stringWithFormat:@"%lu 提问", model.questionCount];
}

#pragma mark - getter

- (UIImageView *)thumbImgV{
    if(!_thumbImgV){
        _thumbImgV = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, 100) imageType:MYImageTypePic];
    }
    return _thumbImgV;
}

- (UIImageView *)headImgV
{
    if (!_headImgV) {
        CGFloat wid = ServiceType == 1 ? 50 : 25;
        _headImgV = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, wid, wid) imageType:MYImageTypeHead];
    }
    return _headImgV;
}

- (UILabel *)nameLb{
    if(!_nameLb){
        _nameLb = [UILabel labelWithFont:MYFont(Font30) color:HEXCOLOR(HSColorBlack)];
    }
    return _nameLb;
}

- (UILabel *)titleLb
{
    if (!_titleLb) {
        _titleLb = [UILabel labelWithFrame:CGRectZero font:MYFont(Font26) color:HEXCOLOR(HSColorGray)];
    }
    return _titleLb;
}

- (UILabel *)descLb
{
    if (!_descLb) {
        _descLb = [UILabel labelWithFrame:CGRectZero font:MYFont(Font32) color:HEXCOLOR(HSColorBlack)];
        _descLb.numberOfLines = 2;
        _descLb.lineBreakMode = NSLineBreakByWordWrapping;
    }
    return _descLb;
}

- (UILabel *)sortLb
{
    if (!_sortLb) {
        _sortLb = [UILabel labelWithFrame:CGRectZero font:MYFont(Font26) color:HEXCOLOR(HSColorBlue)];
    }
    return _sortLb;
}

- (UILabel *)focusLb
{
    if (!_focusLb) {
        _focusLb = [UILabel labelWithFrame:CGRectZero font:MYFont(Font26) color:HEXCOLOR(HSColorGray)];
    }
    return _focusLb;
}

- (UILabel *)askLb
{
    if (!_askLb) {
        _askLb = [UILabel labelWithFrame:CGRectZero font:MYFont(Font26) color:HEXCOLOR(HSColorGray)];
    }
    return _askLb;
}

@end
